<script>
/* eslint-disable */
import TableContainerList from '@/mixins/tableContainerList'
import AjaxStore from '@/utils/store/proxyAjax'
import request from '@/utils/request.js'

export default {
  name: 'dataGroupConfig',
  mixins: [TableContainerList],
  inject: ['Dialog', 'role'],
  props: {
    projectId: Number
  },
  data() {
    return {
      isShowTitle: false,
      tableUniqueId: 'datagroupId',

      autoLoad: false,

      inputPlaceholder: '输入数据组编码或名称搜索',
      containerListTitle: '已分配的数据组',
      getHavedDataGroupsUrl: "/v1/sys/role/getDataGroup",
      store: new AjaxStore({
        url: '/v1/sys/role/queryDatagroup',
        method: 'post'
      }),
      columns: [
        {
          prop: 'datagroupCode',
          label: '编码',
          sortable: true,
          width: '120',
          'show-overflow-tooltip': true,
          'header-align': 'center'
        },
        {
          prop: 'datagroupName',
          label: '名称',
          sortable: true,
          'min-width': '140',
          'show-overflow-tooltip': true,
          'header-align': 'center'
        },
        {
          prop: 'datagroupNote',
          label: '描述',
          sortable: true,
          'min-width': '140',
          'show-overflow-tooltip': true,
          'header-align': 'center'
        },
        {
          prop: 'isEnable',
          label: '状态',
          sortable: true,
          width: '90',
          formatter: (row, column, cellValue) =>
            cellValue == 1 ? '启用' : '未启用',
          'header-align': 'center',
          align: 'center'
        }
      ]
    }
  },
  watch: {
    'Dialog.visible': {
      immediate: true,
      handler(val) {
        val && this._getInfo()
        val &&
          this.$nextTick(() => {
            this.$refs.searchInput.clear()
            this.store._searchParams = {}
            this.$refs.table.load(1)
          })
      }
    },
    data: {
      // immediate: true,
      handler(val) {
        val && this.handleCheckCheckbox()
      }
    }
  },
  methods: {
    getData({ page, limit }) {
      this.store.read({ start: page, limit: limit })
    },
    _getInfo() {
      // this.getData({ page: 1, limit: this.limitNum })
      request({
        url: this.getHavedDataGroupsUrl,
        method: 'post',
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: { roleId: this.role.roleId }
      })
        .then(res => {
          if (res.success) {
            this.containerList = res.data
            this.handleCheckCheckbox()
          } else {
            this.$message({
              type: 'error',
              message: res.message
            })
            this.dialogType = ''
          }
        })
        .catch(error => {
          console.log(error)
        })
    },
    handleInputClick(ev, val) {
      const params = {}
      params.q_name = val
      this.store._searchParams = params
      this.$refs.table.load(1, this.store.limit)
    },
    formaterTagContent(item) {
      return item.datagroupName
    }
  }
}
</script>
